/**
 * Created by zoulu on 15/10/14.
 */

var Manage = {
	init: function() {
//		Manage.get_data();
		$("#from").find("button").click(function(){
			Manage.get_data();
		});

	},
	get_data: function() {
		var user_id = $("#user_id").val();
		if (user_id == "") {
			alert("请输入用户ID");
			return;
		}
		var form_uri = $("#from").find("button").attr("form_uri");
		ajax(form_uri, {
			"user_id": user_id
		}, callback_init_table);
		
	},

	init_table: function(result) {
		if (result != null && result.data != null) {
			var tbody = $("#data_table tbody");
			tbody.empty();
			var educations = result.data.educations;
			var trs = "";
			for (var i = 0; i < educations.length; i++) {
				var education = educations[i];
				trs += ("<tr>");

				var start_at = ("<td>" + formatDate(education.start_at) + "</td>");
				var end_at = ("<td>" + formatDate(education.end_at) + "</td>");
				var school = ("<td>" + education.school + "</td>");
				var certificate = ("<td>" + education.certificate + "</td>");
				var field = ("<td>" + education.field + "</td>");

				trs += (start_at + end_at + school + certificate + field);
				trs += ("</tr>");
			}
			if (educations.length == 0) {
				trs += ("<tr>");
				trs += ("<td colspan='5'>未查询到任何结果</td>");
				trs += ("</tr>");
			}
			tbody.append(trs);

		}
	}
};

function callback_init_table(result) {
	Manage.init_table(result);
}

function callback_init_class(result) {
	Manage.init_class(result);
}

$(function() {
	Manage.init();
})